package com.cduestc.tools;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

public class LocationData {
    Context context;

    public LocationData(Context context){
        this.context = context;
    }

    public String getLocationName(double longitude,double latitude){
        Geocoder geocoder = new Geocoder(context, Locale.getDefault());
        try{
            List<Address> addressList = geocoder.getFromLocation(latitude,longitude,1);
            if(addressList.size() > 0){
                Address address = addressList.get(0);

                 String positionData =
                          address.getLocality();                //市

                return positionData;
            }
        }catch (IOException e){
            e.printStackTrace();
        }
        return "获取定位信息失败";
    }
}
